package com.cdel.akka.util;

import static akka.pattern.Patterns.ask;
import static scala.compat.java8.FutureConverters.toJava;

import java.util.concurrent.CompletableFuture;
import java.util.concurrent.CompletionStage;
import java.util.concurrent.TimeUnit;

import akka.actor.ActorRef;
import scala.concurrent.Future;

public class FutureUtil {

	public static CompletionStage<String> askPong(ActorRef actorRef, String message) {
        Future sFuture = ask(actorRef, message, 1000);
        final CompletionStage<String> cs = toJava(sFuture);
        return cs;
    }

	public static Object get(CompletionStage cs) throws Exception {
        return ((CompletableFuture<String>) cs).get(1500, TimeUnit.MILLISECONDS);
    }

}
